package my.cn.bdqn.life;

import java.util.HashMap;
import java.util.Map;

import my.cn.bdqn.life.myconst.CMD;
import my.cn.bdqn.life.service.FreeService;

import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class RegActivity extends Activity {
	/** Called when the activity is first created. */
	EditText etName, etPassword;
	public static RegActivity currentReg = null;
	public static Map<String,String>map=null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		currentReg = this;
		System.out.println("hello");
		setContentView(R.layout.regist_layout);
		etName = (EditText) findViewById(R.id.userName);
		etPassword = (EditText) findViewById(R.id.userPwd);
	}

	@Override
	public void finish() {
		super.finish();
		currentReg = null;
		map=null;
		stopService(new Intent(this, FreeService.class));
	}

	public void submit(View view) {
		String name = etName.getText().toString();
		String password = etPassword.getText().toString();

		if ("".equals(name) || "".equals(password)) {
			Toast.makeText(this, R.string.input_null, 1).show();
			return;
		}
		try {		
			map=new HashMap();
			map.put("cmd", Integer.toString(CMD.REG));
			map.put("name", name);
			map.put("password", password);
			Intent intent = new Intent(this, FreeService.class);
			intent.putExtra("cmd", CMD.REG);			 
			startService(intent);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}// submit

	public void cancel(View view) {

	}// cancel
	
}
